﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using InvoiceChecking.Entities;
using InvoiceChecking.Data;

#endregion

namespace InvoiceChecking.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="SunReportPrintingProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class SunReportPrintingProviderBaseCore : EntityViewProviderBase<SunReportPrinting>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;SunReportPrinting&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;SunReportPrinting&gt;"/></returns>
		protected static VList&lt;SunReportPrinting&gt; Fill(DataSet dataSet, VList<SunReportPrinting> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<SunReportPrinting>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;SunReportPrinting&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<SunReportPrinting>"/></returns>
		protected static VList&lt;SunReportPrinting&gt; Fill(DataTable dataTable, VList<SunReportPrinting> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					SunReportPrinting c = new SunReportPrinting();
					c.PaymentRef = (Convert.IsDBNull(row["PaymentRef"]))?string.Empty:(System.String)row["PaymentRef"];
					c.PaymentType = (Convert.IsDBNull(row["PaymentType"]))?string.Empty:(System.String)row["PaymentType"];
					c.PaymentDate = (Convert.IsDBNull(row["PaymentDate"]))?string.Empty:(System.String)row["PaymentDate"];
					c.DebitDate = (Convert.IsDBNull(row["DebitDate"]))?string.Empty:(System.String)row["DebitDate"];
					c.PaymentCurrency = (Convert.IsDBNull(row["PaymentCurrency"]))?string.Empty:(System.String)row["PaymentCurrency"];
					c.PayeeNameInEnglish = (Convert.IsDBNull(row["PayeeNameInEnglish"]))?string.Empty:(System.String)row["PayeeNameInEnglish"];
					c.CustomerPaymentReference = (Convert.IsDBNull(row["CustomerPaymentReference"]))?string.Empty:(System.String)row["CustomerPaymentReference"];
					c.PayeeAccountNumber = (Convert.IsDBNull(row["PayeeAccountNumber"]))?string.Empty:(System.String)row["PayeeAccountNumber"];
					c.DebitCurrency = (Convert.IsDBNull(row["DebitCurrency"]))?string.Empty:(System.String)row["DebitCurrency"];
					c.DebitAmount = (Convert.IsDBNull(row["DebitAmount"]))?string.Empty:(System.String)row["DebitAmount"];
					c.DebitAccountNumber = (Convert.IsDBNull(row["DebitAccountNumber"]))?string.Empty:(System.String)row["DebitAccountNumber"];
					c.PaymentAmount = (Convert.IsDBNull(row["PaymentAmount"]))?0.0m:(System.Decimal)row["PaymentAmount"];
					c.ChequeNumber = (Convert.IsDBNull(row["ChequeNumber"]))?string.Empty:(System.String)row["ChequeNumber"];
					c.BatchReference = (Convert.IsDBNull(row["BatchReference"]))?string.Empty:(System.String)row["BatchReference"];
					c.ChequeClearDate = (Convert.IsDBNull(row["ChequeClearDate"]))?string.Empty:(System.String)row["ChequeClearDate"];
					c.BackofficeReference = (Convert.IsDBNull(row["BackofficeReference"]))?string.Empty:(System.String)row["BackofficeReference"];
					c.PaymentStatus = (Convert.IsDBNull(row["PaymentStatus"]))?string.Empty:(System.String)row["PaymentStatus"];
					c.DatePrinted = (Convert.IsDBNull(row["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)row["DatePrinted"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;SunReportPrinting&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;SunReportPrinting&gt;"/></returns>
		protected VList<SunReportPrinting> Fill(IDataReader reader, VList<SunReportPrinting> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					SunReportPrinting entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<SunReportPrinting>("SunReportPrinting",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new SunReportPrinting();
					}
					
					entity.SuppressEntityEvents = true;

					entity.PaymentRef = (System.String)reader[((int)SunReportPrintingColumn.PaymentRef)];
					//entity.PaymentRef = (Convert.IsDBNull(reader["PaymentRef"]))?string.Empty:(System.String)reader["PaymentRef"];
					entity.PaymentType = (System.String)reader[((int)SunReportPrintingColumn.PaymentType)];
					//entity.PaymentType = (Convert.IsDBNull(reader["PaymentType"]))?string.Empty:(System.String)reader["PaymentType"];
					entity.PaymentDate = (reader.IsDBNull(((int)SunReportPrintingColumn.PaymentDate)))?null:(System.String)reader[((int)SunReportPrintingColumn.PaymentDate)];
					//entity.PaymentDate = (Convert.IsDBNull(reader["PaymentDate"]))?string.Empty:(System.String)reader["PaymentDate"];
					entity.DebitDate = (System.String)reader[((int)SunReportPrintingColumn.DebitDate)];
					//entity.DebitDate = (Convert.IsDBNull(reader["DebitDate"]))?string.Empty:(System.String)reader["DebitDate"];
					entity.PaymentCurrency = (System.String)reader[((int)SunReportPrintingColumn.PaymentCurrency)];
					//entity.PaymentCurrency = (Convert.IsDBNull(reader["PaymentCurrency"]))?string.Empty:(System.String)reader["PaymentCurrency"];
					entity.PayeeNameInEnglish = (reader.IsDBNull(((int)SunReportPrintingColumn.PayeeNameInEnglish)))?null:(System.String)reader[((int)SunReportPrintingColumn.PayeeNameInEnglish)];
					//entity.PayeeNameInEnglish = (Convert.IsDBNull(reader["PayeeNameInEnglish"]))?string.Empty:(System.String)reader["PayeeNameInEnglish"];
					entity.CustomerPaymentReference = (reader.IsDBNull(((int)SunReportPrintingColumn.CustomerPaymentReference)))?null:(System.String)reader[((int)SunReportPrintingColumn.CustomerPaymentReference)];
					//entity.CustomerPaymentReference = (Convert.IsDBNull(reader["CustomerPaymentReference"]))?string.Empty:(System.String)reader["CustomerPaymentReference"];
					entity.PayeeAccountNumber = (System.String)reader[((int)SunReportPrintingColumn.PayeeAccountNumber)];
					//entity.PayeeAccountNumber = (Convert.IsDBNull(reader["PayeeAccountNumber"]))?string.Empty:(System.String)reader["PayeeAccountNumber"];
					entity.DebitCurrency = (System.String)reader[((int)SunReportPrintingColumn.DebitCurrency)];
					//entity.DebitCurrency = (Convert.IsDBNull(reader["DebitCurrency"]))?string.Empty:(System.String)reader["DebitCurrency"];
					entity.DebitAmount = (System.String)reader[((int)SunReportPrintingColumn.DebitAmount)];
					//entity.DebitAmount = (Convert.IsDBNull(reader["DebitAmount"]))?string.Empty:(System.String)reader["DebitAmount"];
					entity.DebitAccountNumber = (System.String)reader[((int)SunReportPrintingColumn.DebitAccountNumber)];
					//entity.DebitAccountNumber = (Convert.IsDBNull(reader["DebitAccountNumber"]))?string.Empty:(System.String)reader["DebitAccountNumber"];
					entity.PaymentAmount = (System.Decimal)reader[((int)SunReportPrintingColumn.PaymentAmount)];
					//entity.PaymentAmount = (Convert.IsDBNull(reader["PaymentAmount"]))?0.0m:(System.Decimal)reader["PaymentAmount"];
					entity.ChequeNumber = (System.String)reader[((int)SunReportPrintingColumn.ChequeNumber)];
					//entity.ChequeNumber = (Convert.IsDBNull(reader["ChequeNumber"]))?string.Empty:(System.String)reader["ChequeNumber"];
					entity.BatchReference = (System.String)reader[((int)SunReportPrintingColumn.BatchReference)];
					//entity.BatchReference = (Convert.IsDBNull(reader["BatchReference"]))?string.Empty:(System.String)reader["BatchReference"];
					entity.ChequeClearDate = (System.String)reader[((int)SunReportPrintingColumn.ChequeClearDate)];
					//entity.ChequeClearDate = (Convert.IsDBNull(reader["ChequeClearDate"]))?string.Empty:(System.String)reader["ChequeClearDate"];
					entity.BackofficeReference = (reader.IsDBNull(((int)SunReportPrintingColumn.BackofficeReference)))?null:(System.String)reader[((int)SunReportPrintingColumn.BackofficeReference)];
					//entity.BackofficeReference = (Convert.IsDBNull(reader["BackofficeReference"]))?string.Empty:(System.String)reader["BackofficeReference"];
					entity.PaymentStatus = (System.String)reader[((int)SunReportPrintingColumn.PaymentStatus)];
					//entity.PaymentStatus = (Convert.IsDBNull(reader["PaymentStatus"]))?string.Empty:(System.String)reader["PaymentStatus"];
					entity.DatePrinted = (reader.IsDBNull(((int)SunReportPrintingColumn.DatePrinted)))?null:(System.DateTime?)reader[((int)SunReportPrintingColumn.DatePrinted)];
					//entity.DatePrinted = (Convert.IsDBNull(reader["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)reader["DatePrinted"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="SunReportPrinting"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="SunReportPrinting"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, SunReportPrinting entity)
		{
			reader.Read();
			entity.PaymentRef = (System.String)reader[((int)SunReportPrintingColumn.PaymentRef)];
			//entity.PaymentRef = (Convert.IsDBNull(reader["PaymentRef"]))?string.Empty:(System.String)reader["PaymentRef"];
			entity.PaymentType = (System.String)reader[((int)SunReportPrintingColumn.PaymentType)];
			//entity.PaymentType = (Convert.IsDBNull(reader["PaymentType"]))?string.Empty:(System.String)reader["PaymentType"];
			entity.PaymentDate = (reader.IsDBNull(((int)SunReportPrintingColumn.PaymentDate)))?null:(System.String)reader[((int)SunReportPrintingColumn.PaymentDate)];
			//entity.PaymentDate = (Convert.IsDBNull(reader["PaymentDate"]))?string.Empty:(System.String)reader["PaymentDate"];
			entity.DebitDate = (System.String)reader[((int)SunReportPrintingColumn.DebitDate)];
			//entity.DebitDate = (Convert.IsDBNull(reader["DebitDate"]))?string.Empty:(System.String)reader["DebitDate"];
			entity.PaymentCurrency = (System.String)reader[((int)SunReportPrintingColumn.PaymentCurrency)];
			//entity.PaymentCurrency = (Convert.IsDBNull(reader["PaymentCurrency"]))?string.Empty:(System.String)reader["PaymentCurrency"];
			entity.PayeeNameInEnglish = (reader.IsDBNull(((int)SunReportPrintingColumn.PayeeNameInEnglish)))?null:(System.String)reader[((int)SunReportPrintingColumn.PayeeNameInEnglish)];
			//entity.PayeeNameInEnglish = (Convert.IsDBNull(reader["PayeeNameInEnglish"]))?string.Empty:(System.String)reader["PayeeNameInEnglish"];
			entity.CustomerPaymentReference = (reader.IsDBNull(((int)SunReportPrintingColumn.CustomerPaymentReference)))?null:(System.String)reader[((int)SunReportPrintingColumn.CustomerPaymentReference)];
			//entity.CustomerPaymentReference = (Convert.IsDBNull(reader["CustomerPaymentReference"]))?string.Empty:(System.String)reader["CustomerPaymentReference"];
			entity.PayeeAccountNumber = (System.String)reader[((int)SunReportPrintingColumn.PayeeAccountNumber)];
			//entity.PayeeAccountNumber = (Convert.IsDBNull(reader["PayeeAccountNumber"]))?string.Empty:(System.String)reader["PayeeAccountNumber"];
			entity.DebitCurrency = (System.String)reader[((int)SunReportPrintingColumn.DebitCurrency)];
			//entity.DebitCurrency = (Convert.IsDBNull(reader["DebitCurrency"]))?string.Empty:(System.String)reader["DebitCurrency"];
			entity.DebitAmount = (System.String)reader[((int)SunReportPrintingColumn.DebitAmount)];
			//entity.DebitAmount = (Convert.IsDBNull(reader["DebitAmount"]))?string.Empty:(System.String)reader["DebitAmount"];
			entity.DebitAccountNumber = (System.String)reader[((int)SunReportPrintingColumn.DebitAccountNumber)];
			//entity.DebitAccountNumber = (Convert.IsDBNull(reader["DebitAccountNumber"]))?string.Empty:(System.String)reader["DebitAccountNumber"];
			entity.PaymentAmount = (System.Decimal)reader[((int)SunReportPrintingColumn.PaymentAmount)];
			//entity.PaymentAmount = (Convert.IsDBNull(reader["PaymentAmount"]))?0.0m:(System.Decimal)reader["PaymentAmount"];
			entity.ChequeNumber = (System.String)reader[((int)SunReportPrintingColumn.ChequeNumber)];
			//entity.ChequeNumber = (Convert.IsDBNull(reader["ChequeNumber"]))?string.Empty:(System.String)reader["ChequeNumber"];
			entity.BatchReference = (System.String)reader[((int)SunReportPrintingColumn.BatchReference)];
			//entity.BatchReference = (Convert.IsDBNull(reader["BatchReference"]))?string.Empty:(System.String)reader["BatchReference"];
			entity.ChequeClearDate = (System.String)reader[((int)SunReportPrintingColumn.ChequeClearDate)];
			//entity.ChequeClearDate = (Convert.IsDBNull(reader["ChequeClearDate"]))?string.Empty:(System.String)reader["ChequeClearDate"];
			entity.BackofficeReference = (reader.IsDBNull(((int)SunReportPrintingColumn.BackofficeReference)))?null:(System.String)reader[((int)SunReportPrintingColumn.BackofficeReference)];
			//entity.BackofficeReference = (Convert.IsDBNull(reader["BackofficeReference"]))?string.Empty:(System.String)reader["BackofficeReference"];
			entity.PaymentStatus = (System.String)reader[((int)SunReportPrintingColumn.PaymentStatus)];
			//entity.PaymentStatus = (Convert.IsDBNull(reader["PaymentStatus"]))?string.Empty:(System.String)reader["PaymentStatus"];
			entity.DatePrinted = (reader.IsDBNull(((int)SunReportPrintingColumn.DatePrinted)))?null:(System.DateTime?)reader[((int)SunReportPrintingColumn.DatePrinted)];
			//entity.DatePrinted = (Convert.IsDBNull(reader["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)reader["DatePrinted"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="SunReportPrinting"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="SunReportPrinting"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, SunReportPrinting entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.PaymentRef = (Convert.IsDBNull(dataRow["PaymentRef"]))?string.Empty:(System.String)dataRow["PaymentRef"];
			entity.PaymentType = (Convert.IsDBNull(dataRow["PaymentType"]))?string.Empty:(System.String)dataRow["PaymentType"];
			entity.PaymentDate = (Convert.IsDBNull(dataRow["PaymentDate"]))?string.Empty:(System.String)dataRow["PaymentDate"];
			entity.DebitDate = (Convert.IsDBNull(dataRow["DebitDate"]))?string.Empty:(System.String)dataRow["DebitDate"];
			entity.PaymentCurrency = (Convert.IsDBNull(dataRow["PaymentCurrency"]))?string.Empty:(System.String)dataRow["PaymentCurrency"];
			entity.PayeeNameInEnglish = (Convert.IsDBNull(dataRow["PayeeNameInEnglish"]))?string.Empty:(System.String)dataRow["PayeeNameInEnglish"];
			entity.CustomerPaymentReference = (Convert.IsDBNull(dataRow["CustomerPaymentReference"]))?string.Empty:(System.String)dataRow["CustomerPaymentReference"];
			entity.PayeeAccountNumber = (Convert.IsDBNull(dataRow["PayeeAccountNumber"]))?string.Empty:(System.String)dataRow["PayeeAccountNumber"];
			entity.DebitCurrency = (Convert.IsDBNull(dataRow["DebitCurrency"]))?string.Empty:(System.String)dataRow["DebitCurrency"];
			entity.DebitAmount = (Convert.IsDBNull(dataRow["DebitAmount"]))?string.Empty:(System.String)dataRow["DebitAmount"];
			entity.DebitAccountNumber = (Convert.IsDBNull(dataRow["DebitAccountNumber"]))?string.Empty:(System.String)dataRow["DebitAccountNumber"];
			entity.PaymentAmount = (Convert.IsDBNull(dataRow["PaymentAmount"]))?0.0m:(System.Decimal)dataRow["PaymentAmount"];
			entity.ChequeNumber = (Convert.IsDBNull(dataRow["ChequeNumber"]))?string.Empty:(System.String)dataRow["ChequeNumber"];
			entity.BatchReference = (Convert.IsDBNull(dataRow["BatchReference"]))?string.Empty:(System.String)dataRow["BatchReference"];
			entity.ChequeClearDate = (Convert.IsDBNull(dataRow["ChequeClearDate"]))?string.Empty:(System.String)dataRow["ChequeClearDate"];
			entity.BackofficeReference = (Convert.IsDBNull(dataRow["BackofficeReference"]))?string.Empty:(System.String)dataRow["BackofficeReference"];
			entity.PaymentStatus = (Convert.IsDBNull(dataRow["PaymentStatus"]))?string.Empty:(System.String)dataRow["PaymentStatus"];
			entity.DatePrinted = (Convert.IsDBNull(dataRow["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)dataRow["DatePrinted"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region SunReportPrintingFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SunReportPrinting"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SunReportPrintingFilterBuilder : SqlFilterBuilder<SunReportPrintingColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingFilterBuilder class.
		/// </summary>
		public SunReportPrintingFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SunReportPrintingFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SunReportPrintingFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SunReportPrintingFilterBuilder

	#region SunReportPrintingParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SunReportPrinting"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SunReportPrintingParameterBuilder : ParameterizedSqlFilterBuilder<SunReportPrintingColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingParameterBuilder class.
		/// </summary>
		public SunReportPrintingParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SunReportPrintingParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SunReportPrintingParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SunReportPrintingParameterBuilder
	
	#region SunReportPrintingSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SunReportPrinting"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class SunReportPrintingSortBuilder : SqlSortBuilder<SunReportPrintingColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SunReportPrintingSqlSortBuilder class.
		/// </summary>
		public SunReportPrintingSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion SunReportPrintingSortBuilder

} // end namespace
